<template>
    <a-form ref="formRef" :model="formData">
        <a-form-item field="source" label="来源" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <a-radio-group v-model="formData.source">
                <a-radio v-for="(item, index) in list" :value="index">{{ item }}</a-radio>
            </a-radio-group>
        </a-form-item>
        <a-form-item field="phone" label="用户邮箱" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <a-input v-model="formData.phone" placeholder="请输入用户邮箱" />
        </a-form-item>
        <a-form-item field="number" label="数量" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <a-input-number v-model="formData.number" placeholder="请输入数量" />
        </a-form-item>
    </a-form>
</template>
<script  setup>
import { ref, reactive } from "vue";
import request from '@/api/purchase'
import { Message } from "@arco-design/web-vue";
const emit = defineEmits(["refreshList"]);

const props = defineProps({
    id: [String, Number],
    purchase_id: [String, Number],
    source: [Array, Object]
});

const list = ref({}),
    formData = reactive({
        purchase_id: props.purchase_id,
        source: 1,
        phone: "",
        number: 0
    });
list.value = props.source;

const getDeta = async () => {
    let { data: { data, source } } = await request.table_deta(props.id);
    formData.id = props.id;

    formData.source = String(data.source);
    formData.phone = data.user.phone;
    formData.number = data.number;
    list.value = source;
};
props.id ? getDeta() : "";

const submit = async () => {
    await request.table_save(formData);
    Message.success("保存成功");
    setTimeout(() => emit("refreshList"), 500);
};
defineExpose({ submit });
</script>